#include "ThreadPool.hpp"
#include "Task.hpp"
#include <ctime>

using namespace std;

int main()
{
    prctl(PR_SET_NAME, "master"); // 为线程命名
    const string ops = "+-*/%";
    srand((unsigned long) time(nullptr) ^ getpid() ^ pthread_self());
    // 智能指针
    // 指针内部就是 T*, ↓ 所以这里不需要是指针类型
    // 单例模式线程池（懒汉模式）
    unique_ptr<ThreadPool<Task>> pool(ThreadPool<Task>::getInstance());
    pool->start();

    while (true)
    {
        int left = rand() % 20;
        int right = rand() % 30;
        char op = ops[rand() % 5];
        Task tsk(left, right, op);
        cout << "-----------------------------------------------------" << endl 
             << "For Debug | Thread[" << pthread_self() << "] | 派发任务：" << left << op << right << "=?" << endl;
        pool->push(tsk);
        sleep(1);
    }
    return 0;
}